//
//  PersonInfoViewModel.m
//  CityFire
//
//  Created by Liuyz on 2017/8/4.
//  Copyright © 2017年 刘养柱. All rights reserved.
//

#import "PersonInfoViewModel.h"
#import "UserInfoModel.h"
#import "NSUserDefaults+Tools.h"

@implementation PersonInfoViewModel

- (void)getQueryAdmins:(NSDictionary *)parameter
{
    UserInfoModel *model = [NSKeyedUnarchiver unarchiveObjectWithData:[NSUserDefaults readUserDataWithKey:kNSUSERDEFAULT_KEY_USERINFO]];
    if (model) {
        [YQNetworking requestWithUrl:kQueryAdmins_URL requestType:YQHttpRequestTypePOST refreshRequest:YES cache:NO params:@{@"sessionid" :model.seeeionID, @"username" : model.userName, @"status" : parameter[@"status"], @"pageNo" : parameter[@"pageNo"] ? : @"", @"pageSize" : parameter[@"pageSize"] ? : @""} progressBlock:^(int64_t bytesRead, int64_t totalBytes) {
            //?status=&pageNo=1&pageSize=10&sessionid=1
            //        空：代表查询所有
            //        0：停用
            //        1：启用
            
        } successBlock:^(id response, NSError *responseInfo) {
            
            NSError *error;
            
            self.personsArray = [MTLJSONAdapter modelsOfClass:[PersonInfoModel class] fromJSONArray:response error:&error];
            
            self.responseInfo = error ? error : responseInfo;
            
            //        self.messageModel = msgModel;
            
            if (responseInfo.code == 0) {
                //            [NSUserDefaults removeUserDataWithkey:kNSUSERDEFAULT_KEY_SESSIONID];
                //            [NSUserDefaults removeUserDataWithkey:kNSUSERDEFAULT_KEY_USERINFO];
            }else {
                [SVProgressHUD showErrorWithStatus:responseInfo.domain];
            }
            
        } failBlock:^(NSError *error) {
            self.requestError = error;
            [SVProgressHUD showErrorWithStatus:error.domain];
        }];
    }
    
    
}

@end
